package cn.madog.ui;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.TreeItem;
import javafx.util.StringConverter;

import java.io.File;

public class FileBean extends TreeItem<FileBean> {
    private StringProperty name;
    // 0 处理中, 1 完成, -1 未开始 , 2 失败
    private IntegerProperty status;

    private StringProperty statusStr;

    private File file;

    private StringProperty msg = new SimpleStringProperty();

    public FileBean(File file,String name, Integer status) {
        this.name = new SimpleStringProperty(name);
        this.status = new SimpleIntegerProperty(status);
        this.statusStr = new SimpleStringProperty();
        this.file = file;

        statusStr.bindBidirectional(statusProperty(), new StringConverter<Number>() {
            @Override
            public String toString(Number object) {
                return getStatusStr(object.intValue());
            }

            @Override
            public Number fromString(String string) {

                return null;
            }
        });
    }

    public String getMsg() {
        return msg.get();
    }

    public StringProperty msgProperty() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg.set(msg);
    }

    public FileBean() {
    }

    public String getName() {
        return name.get();
    }

    public StringProperty nameProperty() {
        return name;
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public int getStatus() {
        return status.get();
    }

    public IntegerProperty statusProperty() {
        return status;
    }

    public void setStatus(int status) {
        this.status.set(status);
    }

    public String getStatusStr() {
        return statusStr.get();
    }

    public StringProperty statusStrProperty() {
        return statusStr;
    }

    public void setStatusStr(String statusStr) {
        this.statusStr.set(statusStr);
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    @Override
    public String toString() {
        return "FileBean{" +
                "name=" + name +
                ", status=" + status +
                ", statusStr=" + statusStr +
                ", file=" + file +
                ", msg=" + msg +
                '}';
    }

    private String getStatusStr(Integer status){

        String str = "";

        switch (status){
            case 0 : {
                str = "处理中...";
                break;
            }

            case 1: {
                str = "完成";
                break;
            }
            case 2: {
                str = "失败";
                break;
            }

            default: {
                str = "待处理...";
            }
        }

        return str;

    }

}
